#CSV文件读取器
def csv_reader(file,encoding='UTF-8'):
    from csv import DictReader
    f = open(file,'r',encoding=encoding)
    reader =DictReader(f)
    lst=[]
    for data in reader:
        lst.append(data)
    f.close()
    return lst


#正则表达式提取器
def get_str_by_re(left='\A',right='\Z',string=''):
    from re import search
    result = search(f'{left}(.*?){right}',string)
    try:
        st = result.group(1)
    except:
        st = None
    return st

#SQL语句执行器
def sql_runner(sql):
    from pymysql import connect #导包
    con = connect(host='localhost', user='root', password="root",
                  port=3306)    #创建mysql连接
    cur = con.cursor()          #创建游标
    cur.execute(sql)            #执行sql语句
    con.commit()                #提交
    result = cur.fetchall()     #存储查询结果
    con.close()                 #关闭连接
    return result               #返回查询结果
if __name__ == '__main__':
    sql = 'SELECT * FROM dbshop.dbshop_user WHERE 1=1; '
    sql1 = "DELETE FROM dbshop.dbshop_user WHERE user_name!='huxian';"
    sql_runner(sql1)
    rows = sql_runner(sql)
    for r in rows:
        print(r)

#获取当前系统时间
def sys_time(mode='1'):
    from time import strftime,localtime
    if mode=='1':
        t = strftime('%Y-%m-%d %H:%M:%S',localtime())
    elif mode=='2':
        t = strftime('%Y-%m-%d', localtime())
    elif mode=='3':
        t = strftime('%Y%m%d%H%M%S', localtime())
    else:
        t = strftime('%Y%m%d', localtime())
    return t

if __name__ == '__main__':
    print(sys_time('1'))
    print(sys_time('2'))
    print(sys_time('3'))
    print(sys_time('4'))
    print(sys_time())
